import ApiClient from '@/api/apiClient';

import type { RequestBody } from 'alova';

/**
 * 系统用户项接口
 */
export interface SysUserItem {
  /**
   * 主键ID
   */
  id?: number;
  /**
   * 是否启用 0否 1是
   */
  isEnable?: number;
  /**
   * 姓名
   */
  name?: string;
  /**
   * 手机号
   */
  phone?: string;
  /**
   * 角色ID
   */
  roleId?: number;
  /**
   * 角色名称
   */
  roleName?: string;
  password?: string;
  userId?: number;
  orgId?: number;
  /**
   * 用户名
   */
  userName?: string;
}

/** 获取用户列表 */
export const systemUserListApi = (data: RequestBody) => {
  return ApiClient.Post<API.ListType<SysUserItem>>('/user/page', data, {
    meta: { auth: true },
  });
};

/** 保存或修改用户 */
export const systemUserSaveOrUpdateApi = (data: Merge<RequestBody, SysUserItem>) => {
  return ApiClient.Post(`/user/${data.id ? 'update' : 'save'}`, data, {
    meta: { auth: true },
  });
};

/** 删除用户 */
export const systemUserDeleteApi = (data: Merge<RequestBody, { id: number }>) => {
  return ApiClient.Get(`/user/del?userId=${data.id}`, {
    meta: { auth: true },
  });
};

/** 启用/禁用用户 */
export const systemUserEnableApi = (
  data: Merge<RequestBody, { userId: number; isEnable: number }>
) => {
  return ApiClient.Get('/user/isEnable', {
    params: data,
    meta: { auth: true },
  });
};

/** 重置用户密码 */
export const systemUserResetPasswordApi = (data: Merge<RequestBody, { id: number }>) => {
  return ApiClient.Get('/user/restPwd', {
    params: data,
    meta: { auth: true },
  });
};

/** 获取用户详情 */
export const systemUserDetailApi = (data: Merge<RequestBody, { id: number }>) => {
  return ApiClient.Get<SysUserItem>(`/user/detail?userId=${data.id}`, {
    meta: { auth: true },
  });
};
